import Vue from "vue";
import _this from "../main.js";

const REG_LIST = {
  email: {
    reg: "",
    msg: "邮箱格式有误"
  },
  phone: {
    reg: "",
    msg: "手机号格式有误"
  },
  pwd: {
    reg: "",
    msg: "密码应为6-18为的字母或数字或者混合"
  }
};

Vue.directive("validate", {
  bind(el, binding) {
    el.addEventListener("input", function() {});
    el.addEventListener("blur", function() {
      let type = binding.value;
      let value = el.value;
      value.test(REG_LIST[type].reg) &&
        _this.$vux.toast.text(REG_LIST[type].msg);
    });
  }
});
